import {Component, Inject, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {ActivatedRoute, Router} from '@angular/router';
import {DA_SERVICE_TOKEN, ITokenService} from '@delon/auth';
import {View} from '@antv/data-set';

@Component({
  selector: 'app-profilesOverview',
  templateUrl: './profilesOverview.component.html',
   styleUrls: ['./profilesOverview.component.less']
})
export class ProfilesOverviewComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        public activatedRoute: ActivatedRoute,


        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
    ) { }

    profilesGuid: string; // 工作项guid
    datas: any; // 工作项日期
    token:any;


sourceData = [];

scale = [{
  dataKey: 'percent',
  min: 0,
  formatter: '.0%',
}];


    ngOnInit() {

            this.token  = this.tokenService.get().seniortoken; // 绑定token
             this.profilesGuid = this.activatedRoute.snapshot.params.id;
             this.getData();
    }
        deliveryResults = appConfig.Enumeration.deliveryResults;
//   data = {
//            labels: [],
//             datasets: [
//                 {
//                     data: [],
//                     backgroundColor: [],
//                     hoverBackgroundColor: []
//                 }
//                 ]
//         }
    data= [];
  showloading:boolean = true;
  deliveryResultCountDetails:any; // 按投放申请状态分类统计(饼状图)
  workitemCount:any;
  deliveryCount:any;
  workTypeCount:any;
   forceFit: boolean = true;
  height: number = 400;


  pieStyle = {
    stroke: "#fff",
    lineWidth: 1
  };
  labelConfig = ['percent', {
    offset: -40,
    textStyle: {
      rotate: 0,
      textAlign: 'center',
      shadowBlur: 2,
      shadowColor: 'rgba(0, 0, 0, .45)'
    }
  }];

  getData() {
     let url = '/sProfiles/'+this.profilesGuid+'/general'
        this.utilityService.getData(appConfig.testUrl  + url)
            .subscribe(
                (val) => {
               this.workTypeCount = val.result.workTypeCount;
               console.log(this.workTypeCount)
               this.deliveryResultCountDetails = val.result.deliveryResultCountDetails;
               this.workitemCount = val.result.workitemCount;
               this.deliveryCount = val.result.deliveryCount;
                   this.deliveryResultCountDetails.forEach(element => {
                       this.deliveryResults.forEach(i=>{
                           if(element.deliveryResult === i.key){
                               this.sourceData.push({item:i.value,count:parseInt(element.count)})

                           }
                       })
                   });
           const dv = new View().source(this.sourceData);
                dv.transform({
                type: 'percent',
                field: 'count',
                dimension: 'item',
                as: 'percent'
                });
                this.data = dv.rows;
              console.log(this.sourceData);

                   console.log(this.data);
        },(error)=>{

                 this.nznot.create('error', error.code , error.msg);
        });
    }
    getDetail(it){

    }


}
